package com.lul15834.orderfood.activity.user.adapter;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.lul15834.orderfood.R;
import com.lul15834.orderfood.bean.AddressBean;

import java.math.BigDecimal;
import java.util.List;

/**
 * 显示商家商品的adapter
 */
public class AddressAdapter extends RecyclerView.Adapter<AddressAdapter.AddressViewHolder> {
    private List<AddressBean> list;
    private View parent;
    public AddressAdapter(View parent,List<AddressBean> list){
        this.list=list;
        this.parent=parent;
    }


    @NonNull
    @Override
    public AddressAdapter.AddressViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater inflater=LayoutInflater.from(parent.getContext());
        View convertView=inflater.inflate(R.layout.list_user_address,parent,false);

        return new AddressViewHolder(convertView);
    }

    @Override
    public void onBindViewHolder(@NonNull AddressAdapter.AddressViewHolder holder, int position) {
        AddressBean tem=list.get(position);
        holder.name.setText(tem.getsUserName());
        holder.address.setText(tem.getsUserAddress());
        holder.phone.setText(tem.getsUserPhone());
        TextView people=parent.findViewById(R.id.buy_food_dialog_people);
        TextView address=parent.findViewById(R.id.buy_food_dialog_address);
        TextView phone=parent.findViewById(R.id.buy_food_dialog_phone);

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                people.setText(tem.getsUserName());
                address.setText(tem.getsUserAddress());
                phone.setText(tem.getsUserPhone());
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    static class AddressViewHolder extends RecyclerView.ViewHolder{
        TextView name;
        TextView address;
        TextView phone;
        View itemView;
        public AddressViewHolder(@NonNull View itemView) {
            super(itemView);
            name=itemView.findViewById(R.id.list_user_address_name);
            address=itemView.findViewById(R.id.list_user_address);
            phone=itemView.findViewById(R.id.list_user_address_phone);
            this.itemView=itemView;
        }
    }


}

